<?php

/**
 * 携程
 * @author lzp300
 * @copyright 2015-03-26
 */
class toQmgHotelLog{
	function SignUtil($serviceName="1",$accountKey="qingmangguokey",$version="1.1.0",$accountID="qingmangguo"){
        $reqTime=date('Y-m-d',time());
        
        $resuoce=array();
        $resuoce['state']=0;
        $resuoce['string']="";
        
        $originalArray=array();
        $originalArray['Version']=$version;
        $originalArray['AccountID']=$accountID;
        $originalArray['ReqTime']=$reqTime;
        if($serviceName){
            $originalArray['ServiceName']=$serviceName;
            ksort($originalArray);
            $sortedArray="";
            foreach($originalArray as $k=>$v){
                $sortedArray.=$k.'='.$v.'&';
            }
            $sortedArray=trim($sortedArray,'&');
            $keywords=md5($sortedArray.$accountKey);
            $resuoce['state']=1;
            $resuoce['string']['version']=$version;
            $resuoce['string']['accountId']=$accountID;
            $resuoce['string']['serviceName']=$serviceName;
            $resuoce['string']['sign']=$keywords;
            $resuoce['string']['reqTime']=$reqTime;
            //var_dump($resuoce);
        }else{
            $resuoce['string']='接口方法名错误！';
        }
        return $resuoce;
    }
    
	//日志记录
    function setLogs($logs,$path="/data/Logs/toQmgHotelLog/"){
        $fleName=$_SERVER['DOCUMENT_ROOT'].$path.date('Y-m-d',time())."_".date('H:i',time()).".txt";
        $th_time=fopen($fleName,"a");
        fwrite($th_time,date('Y-m-d H:i:s',time())."\r\n".$logs."\r\n\r\n\r\n");
        fclose($th_time);
    }
	
    /**
     * curl 传输   //测试：120.24.75.164:8999---正式：120.24.166.230:8999
     */
    function curl($post_data,$url="http://120.24.166.230:8999/PmsInterfaceConnections/PmsDataInterFace/getPmsMethod"){
        $ch = curl_init();
        //print_r($ch);
        curl_setopt ( $ch, CURLOPT_URL, $url );
        curl_setopt ( $ch, CURLOPT_POST, 1 );
        curl_setopt ( $ch, CURLOPT_HEADER, 0 );
        curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
        curl_setopt ( $ch, CURLOPT_TIMEOUT,60);
        curl_setopt ( $ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=utf-8"));
        curl_setopt ( $ch, CURLOPT_POSTFIELDS, $post_data );
        $return = curl_exec ( $ch );
        
		$logs="调用地址：".$url."\r\n接收数据：".$return."\r\n发送数据：".$post_data;
        $this->setLogs($logs);
		
        curl_close ( $ch );
        $return=json_decode($return,true);
        if($return){
            $body=isset($return['body'])?$return['body']:'';
            $head=isset($return['head'])?$return['head']:'';
            if($head&&is_array($head)&&$head['status']==0&&$head['responseCode']==0000){
				return $body;
			}else{
				return "数据错误，请联系技术人员！";
			}
        }
		return "获取内容失败！";
    }
    
    /**
     * 公共调用
     */
    function thall($actionName,$body){
		set_time_limit(0);
        $resuoce=$this->SignUtil($actionName);
        if($resuoce['state']==1){
            $post_data=json_encode(array("head"=>$resuoce['string'],"body"=>$body));
            $contArray=$this->curl($post_data);
            return $contArray;
        }else{
            return $resuoce['string'];
        }
    }
	
    //房型价格 添加、修改 发送OSII
    function typePrice($body){
		$arr=$this->thall("SetRoomPrice",$body);
    }
	
    //设置房态 添加、修改  发送OSII
    function roomstatus($body){
		$arr=$this->thall("SetRoomInfo",$body);
    }
	
	/*//酒店添加、修改  发送 OSII
    function hotels($body){
		$arr=$this->thall("GetHotelInfo",$body);
    }
    
    //房型添加、修改  发送OSII
    function rooms($body){
		$arr=$this->thall("GetRoomTypeInfo",$body);
    }
    
    //图片添加、修改 发送OSII
    function imgs($body){
		$arr=$this->thall("GetHotelImageInfo",$body);
    }*/
    
}